package com.literature.threeGroup.service.impl;

import com.literature.threeGroup.mapper.CoverMapper;
import com.literature.threeGroup.mapper.OrganMapper;
import com.literature.threeGroup.mapper.ParamMapper;
import com.literature.threeGroup.mapper.ResourceInfoMapper;
import com.literature.threeGroup.service.CommonService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;

/**
 * @ClassName CommonService
 * @Description: TODO
 * @Author ForeverLoveT
 * @Date 2020/1/9
 * @Version V1.0
 **/
@Service
public class CommonServiceImpl implements CommonService {

    @Autowired
    private ParamMapper paramMapper;
    @Autowired
    private ResourceInfoMapper resourceInfoMapper;
    @Autowired
    private CoverMapper coverMapper;
    @Autowired
    private OrganMapper organMapper;
    public String getParamNameById(String ids){
        if (StringUtils.isEmpty(ids)){
            return "-";
        }
        String paramName = paramMapper.findPid(Arrays.asList(ids.split(",")));
        return StringUtils.isEmpty(paramName) ? "-" : paramName;
    }
    //批量删除和修改状态
    public void UpdateStatus(String[] ids,int distributionStatus){
        if (ids==null){
            return ;
        }
        resourceInfoMapper.UpdateStatus(ids,distributionStatus);

    }
    //查询套名称
    public String findCoverName(String coverids){
        if (StringUtils.isEmpty(coverids)){
            return "-";
        }
        String coverName = coverMapper.findCoverName(Arrays.asList(coverids.split(",")));
        return StringUtils.isEmpty(coverName) ? "-" : coverName;
    }
    //获取单位名称
    public String findOrganName(String organid){
        if (StringUtils.isEmpty(organid)){
            return "-";
        }
        String coverName = organMapper.findOrganName(organid);
        return StringUtils.isEmpty(coverName) ? "-" : coverName;
    }
}
